<template>
  <div class="top">
      <div class="left">
        <el-button type="info" size="mini" icon="el-icon-s-fold" 
        v-if="!ishidden" 
        style="font-size: 25px;margin: 4px 15px;" 
        v-on:click="changemenu"></el-button>
        <el-button type="info" size="mini" icon="el-icon-s-unfold" 
        v-else 
        style="font-size: 25px;margin: 4px 15px;"
        v-on:click="changemenu"></el-button>
    </div>
    <div class="right">
    <el-dropdown @command="handleCommand" style="margin:4px 20px 0px 0px">
    <span class="el-dropdown-link" style="margin-left: 50px;">
      <el-avatar :size="40" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
    </span>
    <el-dropdown-menu slot="dropdown">
    <el-dropdown-item command="A">个人中心</el-dropdown-item>
    <el-dropdown-item divided command="E">退出</el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>
        </div>
    </div>
</template>

<script>
import Cookie from 'js-cookie'
import { mapMutations,mapState } from 'vuex'
export default {
    name:'top',
    data(){
      return {
        
      }
    },
    computed:{
      ...mapState('menu',['ishidden'])
    },
    methods:{
      ...mapMutations('menu',['changeishidden']),
      changemenu(){
        this.ishidden = !this.ishidden,
        this.changeishidden()
      },
      handleCommand(command){
        if(command==='E'){
          this.$confirm('是否确定退出系统?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          Cookie.remove('username')
          Cookie.remove('usertype')
          Cookie.remove('menu')
          Cookie.remove('route')
          this.$router.push('login')
          this.$message({
            type: 'success',
            message: '已退出!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出'
          });          
        });
        }
        else{
          this.$message('作者正在加急制作中(#`O′)')
        }
      }
    }
}
</script>

<style>
.top{
  background-color:#393b3d;
  display:flex;
  justify-content: space-between;
  height: 50px;
}

</style>